<?php

namespace app\api\controller\event;
use app\api\service\event\ReleaseService;
use think\Request;

class Release
{
    protected $Service;
    public function __construct()
    {
        $this->Service = ReleaseService::getInstance();
    }

    /**
     * @auth('查询分发的数据列表','分发管理')
     * @param Request $request
     * @param('page','页数','require')
     * @return \think\response\Json
     */
    public function getEventList(Request $request){
        $params = $request->get();
        $result = $this->Service->getEventList($params);
        return writeJson(201, $result, '数据列表');
    }


    /**
     * @auth('使用分组查询分发','分发管理')
     * @param Request $request
     * @param('group_id','分组id','require')
     * @return \think\response\Json
     */
    public function getEventGroupList(Request $request){
        $params = $request->get();
        $result = $this->Service->getEventGroupList($params);
        return writeJson(201, $result, '数据列表');
    }


    /**
     * @auth('回填地址','分发管理')
     * @param Request $request
     * @param('id','文章id','require')
     * @param('url','地址','require')
     * @return \think\response\Json
     */
    public function backfillUrl(Request $request){
        $params = $request->param();
        $this->Service->backfillUrl($params);
        return writeJson(201, '', '回填成功');
    }

//    /**
//     * 抖音图文分享
//     * @param Request $request
//     * @param('id','文章id','require')
//     * @return \think\response\Json
//     */
//    public function douyinDistribute(Request $request){
//        $params = $request->get();
//        $result = $this->Service->douyinDistribute($params);
//        return writeJson(201, $result, '回填成功');
//    }


//    /**
//     * 抖音回调
//     * @param Request $request
//     * @return \think\response\Json
//     */
//    public function douyinChallenge(Request $request){
//        $params = $request->post();
//        if ($params['event'] == 'verify_webhook'){
//            $data = [
//                "challenge"=>$params['content']['challenge']
//            ];
//            return $data;
//        }
//
//        if ($params['event'] == "create_video"){
//            $this->Service->douyinChallenge($params);
//        }
//
//    }

    /**
     * @auth('检测公众号关注','分发管理')
     * @param Request $request
     * @param('code','code','require')
     * @return \think\response\Json
     */
    public function follow(Request $request){
        $params = $request->get();
        $this->Service->follow($params);
        return writeJson(200,true,'成功！');
    }


    /**
     * @auth('分发账号绑定公众号','分发管理')
     * @param Request $request
     * @return \think\response\Json
     */
    public function bindAccount(Request $request){
        $params = $request->param();
        $this->Service->bindAccount($params);
        return writeJson(200,true,'绑定成功！');
    }


    /**
     * @auth('查询账号是否绑定公众号','分发管理')
     * @param Request $request
     * @return \think\response\Json
     */
    public function getBindAccount(Request $request){
        $params = $request->get();
        $this->Service->getBindAccount($params);
        return writeJson(200,true,'账号已绑定！');
    }


    /**
     * @auth('分发账号积分查询','分发管理')
     * @param Request $request
     * @return \think\response\Json
     */
    public function getIntegral(Request $request){
        $params = $request->get();
        $res = $this->Service->getIntegral($params);
        return writeJson(200,$res,'数据！');
    }
}
